let express = require('express');
let router = express.Router();
const md5  = require('md5');
/* GET home page. */


/**
 * 用户注册
 */
router.all('/register', function(req, res, next) {
   global['bean'].UserService.registerUser("t_user",{t_id:22,t_userName:'dd1d',t_passWord:'你好'}).then(data=>{
       res.json(res.wrap(20000,'登录',data))
   }).catch(e=>{
       next(e);
   });
});
/**
 * 用户登录
 */
router.all('/login', function(req, res, next) {
    global['bean'].UserService.userLogin("t_user",'a','b').then(data=>{
        const user = data[0];
        console.log(user);
        let err = undefined;
        if(user){
            if(user.t_state == 0){
                if( user.t_passWord == md5('b')){
                    res.json(res.wrap(20000,'登录'));
                    return;
                }else{
                    err ={message:"密码不正确!"}
                }
            }else{
                err ={message:"用户禁用，请联系管理员!"}
            }
        }else {
            err ={message:"用户不存在!"}
        }
       next(err);
    }).catch(e=>{
        next(e);
    });
});

module.exports = router;
